#Note: this code estimates Model1  as reported in Tables A.4-A.17 and Tables A.20-A.21 of the Supplemental Appendix
#   To do so, it reads-in the Stata dta files "MainMalariaDatasetStata11.dta" and "MonMalariaDatasetStata11.dta"
#   and then prints the relevant model output to screen.


################################################################
#############################Set-up#############################
################################################################

#load necessary packages
library(plm)
library(doBy)
library(plyr)
library(readstata13)

#Set working directory
setwd("")

##########################################################################################################
#######################Models A.4, A.6, A.8, A.10, A.12, A.14, A.16, and A.20#############################
##########################################################################################################

#Import dyadic dataset
dyad.dat <- read.dta13("MainMalariaDatasetStata11.dta")


###############
###Table A.4###
###############

##Keep only variables of interest
full.dyad <- dyad.dat[,c("dr_1_at_2_m","Lmalaria_interp_2_m","Llog_trade_m","Ldr_2_at_1_m","Llog_gdppc_1_m","Llog_gdppc_2_m","Ls2_m","Lln_cinc_1_m","Lln_cinc_2_m","Ldem_int_m","Ldemocracy_1_m","Ldemocracy_2_m","ddyad","year5")]

#Convert data to pgmm formal
pgmm.full.dyad <- pdata.frame(full.dyad, index=c("ddyad", "year5"))

#set seed
set.seed(50)

#Run and summarize model
gmm.full.dyad <- pgmm(dr_1_at_2_m ~ Lmalaria_interp_2_m+
                        Llog_trade_m+Ldr_2_at_1_m+Llog_gdppc_1_m+Llog_gdppc_2_m+
                        Ls2_m+Lln_cinc_1_m+Lln_cinc_2_m+Ldem_int_m+
                        Ldemocracy_1_m+Ldemocracy_2_m| 
                        lag(dr_1_at_2_m , 2:5)+lag(Lmalaria_interp_2_m,2:5),
                      data = pgmm.full.dyad, 
                      effect = "twoway", transformation= "ld", model = "onestep")
summary(gmm.full.dyad)

##Number of observations
full.dyad.na <- na.omit(dyad.dat[,c("dr_1_at_2_m","Lmalaria_interp_2_m","Llog_trade_m","Ldr_2_at_1_m","Llog_gdppc_1_m","Llog_gdppc_2_m","Ls2_m","Lln_cinc_1_m","Lln_cinc_2_m","Ldem_int_m","Ldemocracy_1_m","Ldemocracy_2_m","ddyad","year5")])
length(full.dyad.na$dr_1_at_2_m)

###############
###Table A.6###
###############

##Keep only variables of interest
nl.dyad <- dyad.dat[,c("dr_1_at_2_m","malaria_interp_2_m","log_trade_m","dr_2_at_1_m","log_gdppc_1_m","log_gdppc_2_m","s2_m","ln_cinc_1_m","ln_cinc_2_m","dem_int_m","democracy_1_m","democracy_2_m","ddyad","year5")]

#Convert data to pgmm formal
pgmm.nl.dyad <- pdata.frame(nl.dyad, index=c("ddyad", "year5"))

#set seed
set.seed(50)

#Run and summarize model
gmm.nl.dyad <- pgmm(dr_1_at_2_m ~ malaria_interp_2_m+
                      log_trade_m+dr_2_at_1_m+log_gdppc_1_m+log_gdppc_2_m+
                      s2_m+ln_cinc_1_m+ln_cinc_2_m+dem_int_m+
                      democracy_1_m+democracy_2_m| 
                      lag(dr_1_at_2_m , 2:5)+lag(malaria_interp_2_m,2:5),
                    data = pgmm.nl.dyad, 
                    effect = "twoway", transformation= "ld", model = "onestep")
summary(gmm.nl.dyad)

##Number of observations
nl.dyad.na <- na.omit(dyad.dat[,c("dr_1_at_2_m","malaria_interp_2_m","log_trade_m","dr_2_at_1_m","log_gdppc_1_m","log_gdppc_2_m","s2_m","ln_cinc_1_m","ln_cinc_2_m","dem_int_m","democracy_1_m","democracy_2_m","ddyad","year5")])
length(nl.dyad.na$dr_1_at_2_m)

###############
###Table A.8###
###############


##Keep only variables of interest
nl.dyad <- dyad.dat[,c("dr_1_at_2_m","malaria_interp_2_m","log_trade_m","dr_2_at_1_m","log_gdppc_1_m","log_gdppc_2_m","s2_m","ln_cinc_1_m","ln_cinc_2_m","dem_int_m","democracy_1_m","democracy_2_m","ddyad","year5")]

#Convert data to pgmm formal
pgmm.nl.dyad <- pdata.frame(nl.dyad, index=c("ddyad", "year5"))

#set seed
set.seed(50)

###Run model
gmm.nl.dyad <- pgmm(dr_1_at_2_m ~ malaria_interp_2_m+
                      log_trade_m+dr_2_at_1_m+log_gdppc_1_m+log_gdppc_2_m+
                      s2_m+ln_cinc_1_m+ln_cinc_2_m+dem_int_m+
                      democracy_1_m+democracy_2_m| 
                      lag(dr_1_at_2_m , 2:5)+lag(malaria_interp_2_m,2:5),
                    data = pgmm.nl.dyad, 
                    effect = "twoway", transformation= "ld", model = "onestep")
summary(gmm.nl.dyad)

##Number of observations
nl.dyad.na <- na.omit(dyad.dat[,c("dr_1_at_2_m","malaria_interp_2_m","log_trade_m","dr_2_at_1_m","log_gdppc_1_m","log_gdppc_2_m","s2_m","ln_cinc_1_m","ln_cinc_2_m","dem_int_m","democracy_1_m","democracy_2_m","ddyad","year5")])
length(nl.dyad.na$dr_1_at_2_m)


################
###Table A.10###
################

##Keep only variables of interest
omit.dyad <- dyad.dat[,c("dr_1_at_2_m","Lmalaria_interp_2_m","Llog_trade_m","Ldr_2_at_1_m","Llog_gdppc_1_m","Llog_gdppc_2_m","Ls2_m","Lln_cinc_1_m","Lln_cinc_2_m","Ldem_int_m","Ldemocracy_1_m","Ldemocracy_2_m","ddyad","year5")]

##Remove non-malarial sates 
omit.dyad <- subset(omit.dyad, Lmalaria_interp_2_m>0)
#Convert data to pgmm formal
pgmm.omit.dyad <- pdata.frame(omit.dyad, index=c("ddyad", "year5"))

#set seed
set.seed(50)

#Run and summarize model
gmm.omit.dyad <- pgmm(dr_1_at_2_m ~ Lmalaria_interp_2_m+
                        Llog_trade_m+Ldr_2_at_1_m+Llog_gdppc_1_m+Llog_gdppc_2_m+
                        Ls2_m+Lln_cinc_1_m+Lln_cinc_2_m+Ldem_int_m+
                        Ldemocracy_1_m+Ldemocracy_2_m| 
                        lag(dr_1_at_2_m , 2:5)+lag(Lmalaria_interp_2_m,2:5),
                      data = pgmm.omit.dyad, 
                      effect = "twoway", transformation= "ld", model = "onestep")
summary(gmm.omit.dyad)

##Number of observations
omit.dyad.na <- na.omit(omit.dyad)
length(omit.dyad.na$dr_1_at_2_m)

################
###Table A.12###
################

##Keep only variables of interest
ni.dyad <- dyad.dat[,c("dr_1_at_2_m","Lcid_malaria_2_m","Llog_trade_m","Ldr_2_at_1_m","Llog_gdppc_1_m","Llog_gdppc_2_m","Ls2_m","Lln_cinc_1_m","Lln_cinc_2_m","Ldem_int_m","Ldemocracy_1_m","Ldemocracy_2_m","ddyad","year5")]

#Convert data to pgmm formal
pgmm.ni.dyad <- pdata.frame(ni.dyad, index=c("ddyad", "year5"))

#set seed
set.seed(50)

#Run and summarize model NOTE: we are forced to rely on deeper lags considering lack of variations on malaria for the first several periods of analysis due to intrapoliation
gmm.ni.dyad <- pgmm(dr_1_at_2_m ~ Lcid_malaria_2_m+
                      Llog_trade_m+Ldr_2_at_1_m+Llog_gdppc_1_m+Llog_gdppc_2_m+
                      Ls2_m+Lln_cinc_1_m+Lln_cinc_2_m+Ldem_int_m+
                      Ldemocracy_1_m+Ldemocracy_2_m| 
                      lag(dr_1_at_2_m , 5:99)+lag(Lcid_malaria_2_m,5:99),
                    data = pgmm.ni.dyad, 
                    effect = "twoway", transformation= "ld", model = "onestep")
summary(gmm.ni.dyad)

##Number of observations
ni.dyad.na <- na.omit(dyad.dat[,c("dr_1_at_2_m","Lcid_malaria_2_m","Llog_trade_m","Ldr_2_at_1_m","Llog_gdppc_1_m","Llog_gdppc_2_m","Ls2_m","Lln_cinc_1_m","Lln_cinc_2_m","Ldem_int_m","Ldemocracy_1_m","Ldemocracy_2_m","ddyad","year5")])
length(ni.dyad.na$dr_1_at_2_m)

################
###Table A.14###
################

##Keep only variables of interest
pop.dyad <- dyad.dat[,c("dr_1_at_2_m","Lmalaria_interp_pop_2_m","Llog_trade_m","Ldr_2_at_1_m","Llog_gdppc_1_m","Llog_gdppc_2_m","Ls2_m","Lln_cinc_1_m","Lln_cinc_2_m","Ldem_int_m","Ldemocracy_1_m","Ldemocracy_2_m","ddyad","year5")]

#Convert data to pgmm formal
pgmm.pop.dyad <- pdata.frame(pop.dyad, index=c("ddyad", "year5"))

#set seed
set.seed(50)

#Run and summarize model
gmm.pop.dyad <- pgmm(dr_1_at_2_m ~ Lmalaria_interp_pop_2_m+
                       Llog_trade_m+Ldr_2_at_1_m+Llog_gdppc_1_m+Llog_gdppc_2_m+
                       Ls2_m+Lln_cinc_1_m+Lln_cinc_2_m+Ldem_int_m+
                       Ldemocracy_1_m+Ldemocracy_2_m| 
                       lag(dr_1_at_2_m , 2:5)+lag(Lmalaria_interp_pop_2_m,2:5),
                     data = pgmm.pop.dyad, 
                     effect = "twoway", transformation= "ld", model = "onestep")
summary(gmm.pop.dyad)

##Number of observations
pop.dyad.na <- na.omit(dyad.dat[,c("dr_1_at_2_m","Lmalaria_interp_pop_2_m","Llog_trade_m","Ldr_2_at_1_m","Llog_gdppc_1_m","Llog_gdppc_2_m","Ls2_m","Lln_cinc_1_m","Lln_cinc_2_m","Ldem_int_m","Ldemocracy_1_m","Ldemocracy_2_m","ddyad","year5")])
length(pop.dyad.na$dr_1_at_2_m)


################
###Table A.16###
################

##Keep only variables of interest
exp.dyad <- dyad.dat[,c("dr_1_at_2_m","L_total_exposure_2","Llog_trade_m","Ldr_2_at_1_m","Llog_gdppc_1_m","Llog_gdppc_2_m","Ls2_m","Lln_cinc_1_m","Lln_cinc_2_m","Ldem_int_m","Ldemocracy_1_m","Ldemocracy_2_m","ddyad","year5")]

#Convert data to pgmm formal
pgmm.exp.dyad <- pdata.frame(exp.dyad, index=c("ddyad", "year5"))

#set seed
set.seed(50)

#Run and summarize model
gmm.exp.dyad <- pgmm(dr_1_at_2_m ~ L_total_exposure_2+
                       Llog_trade_m+Ldr_2_at_1_m+Llog_gdppc_1_m+Llog_gdppc_2_m+
                       Ls2_m+Lln_cinc_1_m+Lln_cinc_2_m+Ldem_int_m+
                       Ldemocracy_1_m+Ldemocracy_2_m| 
                       lag(dr_1_at_2_m , 2:5)+lag(L_total_exposure_2,2:5),
                     data = pgmm.exp.dyad, 
                     effect = "twoway", transformation= "ld", model = "onestep")
summary(gmm.exp.dyad)

##Number of observations
exp.dyad.na <- na.omit(dyad.dat[,c("dr_1_at_2_m","L_total_exposure_2","Llog_trade_m","Ldr_2_at_1_m","Llog_gdppc_1_m","Llog_gdppc_2_m","Ls2_m","Lln_cinc_1_m","Lln_cinc_2_m","Ldem_int_m","Ldemocracy_1_m","Ldemocracy_2_m","ddyad","year5")])
length(exp.dyad.na$dr_1_at_2_m)


################
###Table A.20###
################

##Keep only variables of interest
cont.dyad <- dyad.dat[,c("dr_1_at_2_m","Lmalaria_interp_2_m","Llog_trade_m","Ldr_2_at_1_m","Llog_gdppc_1_m","Llog_gdppc_2_m","Ls2_m","Lln_cinc_1_m","Lln_cinc_2_m","Ldem_int_m","Ldemocracy_1_m","Ldemocracy_2_m","Linternal_conf_2_m","Lexternal_conf_2_m","Lln_irst_2_m","Lln_milex_2_m","Lln_milper_2_m","Lln_pec_2_m","Lln_upop_2_m","entryy_2_m","ddyad","year5")]

#Convert data to pgmm formal
pgmm.cont.dyad <- pdata.frame(cont.dyad, index=c("ddyad", "year5"))

#set seed
set.seed(50)

#Run and summarize model NOTE: we lose one period so we rely on deeper lags
gmm.cont.dyad <- pgmm(dr_1_at_2_m ~ Lmalaria_interp_2_m+Llog_trade_m+
                        Ldr_2_at_1_m+Llog_gdppc_1_m+Llog_gdppc_2_m+Ls2_m+Lln_cinc_1_m+Lln_cinc_2_m+Ldem_int_m+
                        Ldemocracy_1_m+Ldemocracy_2_m+Linternal_conf_2_m+Lexternal_conf_2_m+Lln_irst_2_m+Lln_milex_2_m+
                        Lln_milper_2_m+Lln_pec_2_m+Lln_upop_2_m+entryy_2_m| 
                        lag(dr_1_at_2_m , 3:6)+lag(Lmalaria_interp_2_m,3:6),
                      data = pgmm.cont.dyad, 
                      effect = "twoway", transformation= "ld", model = "onestep")
summary(gmm.cont.dyad)

###Number of observations:
cont.dyad.na <- na.omit(dyad.dat[,c("dr_1_at_2_m","Lmalaria_interp_2_m","Llog_trade_m","Ldr_2_at_1_m","Llog_gdppc_1_m","Llog_gdppc_2_m","Ls2_m","Lln_cinc_1_m","Lln_cinc_2_m","Ldem_int_m","Ldemocracy_1_m","Ldemocracy_2_m","Linternal_conf_2_m","Lexternal_conf_2_m","Lln_irst_2_m","Lln_milex_2_m","Lln_milper_2_m","Lln_pec_2_m","Lln_upop_2_m","entryy_2_m","ddyad","year5")])
length(cont.dyad.na$dr_1_at_2_m)




##########################################################################################################
#######################Models A.5, A.7, A.9, A.11, A.13, A.15, A.17, and A.21#############################
##########################################################################################################

#Import monadic dataset
mon.dat <- read.dta13("MonMalariaDatasetStata11.dta")

##############
###Model A5###
##############

##Keep only variables of interest
full.mon <- mon.dat[,c("dr_1_at_2_m","Lmalaria_interp_2_m","Llog_trade_m","Llog_gdppc_2_m","Lln_cinc_2_m","Ldemocracy_2_m","cowcode_2","year5")]

#Convert data to pgmm formal
pgmm.full.mon <- pdata.frame(full.mon, index=c("cowcode_2", "year5"))

#set seed
set.seed(50)

#run and summaize model
gmm.full.mon <- pgmm(dr_1_at_2_m~Lmalaria_interp_2_m+Llog_trade_m+Llog_gdppc_2_m+Lln_cinc_2_m+
                       Ldemocracy_2_m| 
                       lag(dr_1_at_2_m, 2:5)+lag(Lmalaria_interp_2_m,2:5),
                     data = pgmm.full.mon, 
                     effect = "twoway", transformation= "ld", model = "onestep")
summary(gmm.full.mon)

##Number of observations
full.mon.na <- na.omit(mon.dat[,c("dr_1_at_2_m","Lmalaria_interp_2_m","Llog_trade_m","Llog_gdppc_2_m","Lln_cinc_2_m","Ldemocracy_2_m","cowcode_2","year5")])
length(full.mon.na$dr_1_at_2_m)


###############
###Table A.7###
###############

##Keep only variables of interest
nl.mon <- mon.dat[,c("dr_1_at_2_m","malaria_interp_2_m","log_trade_m","log_gdppc_2_m","ln_cinc_2_m","democracy_2_m","cowcode_2","year5")]

#Convert data to pgmm formal
pgmm.nl.mon <- pdata.frame(nl.mon, index=c("cowcode_2", "year5"))

#set seed
set.seed(50)

###Run model
gmm.nl.mon <- pgmm(dr_1_at_2_m ~ malaria_interp_2_m+log_trade_m+log_gdppc_2_m+ln_cinc_2_m+
                     democracy_2_m| 
                     lag(dr_1_at_2_m , 2:5)+lag(malaria_interp_2_m,2:5),
                   data = pgmm.nl.mon, 
                   effect = "twoway", transformation= "ld", model = "onestep")
summary(gmm.nl.mon)

##Number of observations
nl.mon.na <- na.omit(mon.dat[,c("dr_1_at_2_m","malaria_interp_2_m","log_trade_m","log_gdppc_2_m","ln_cinc_2_m","democracy_2_m","cowcode_2","year5")])
length(nl.mon.na$dr_1_at_2_m)

###############
###Table A.9###
###############

##Keep only variables of interest
full.mon <- mon.dat[,c("dr_1_at_2_m","Lmalaria_interp_2_m","Llog_trade_m","Llog_gdppc_2_m","Lln_cinc_2_m","Ldemocracy_2_m","cowcode_2","year5")]

#Convert data to pgmm formal
pgmm.full.mon <- pdata.frame(full.mon, index=c("cowcode_2", "year5"))

#set seed
set.seed(50)

#Run and summarize model
gmm.full.mon <- pgmm(dr_1_at_2_m~Lmalaria_interp_2_m+Llog_trade_m+Llog_gdppc_2_m+Lln_cinc_2_m+
                       Ldemocracy_2_m| 
                       lag(dr_1_at_2_m, 2:5)+lag(Lmalaria_interp_2_m,2:5),
                     data = pgmm.full.mon, 
                     effect = "twoway", transformation= "ld", model = "onestep")
summary(gmm.full.mon)

##Number of observations
full.mon.na <- na.omit(mon.dat[,c("dr_1_at_2_m","Lmalaria_interp_2_m","Llog_trade_m","Llog_gdppc_2_m","Lln_cinc_2_m","Ldemocracy_2_m","cowcode_2","year5")])
length(full.mon.na$dr_1_at_2_m)

################
###Table A.11###
################

##Keep only variables of interest
omit.mon <- mon.dat[,c("dr_1_at_2_m","Lmalaria_interp_2_m","Llog_trade_m","Llog_gdppc_2_m","Lln_cinc_2_m","Ldemocracy_2_m","cowcode_2","year5")]

##Remove non-malarial sates 
omit.mon <- subset(omit.mon, Lmalaria_interp_2_m>0)
#Convert data to pgmm formal
pgmm.omit.mon <- pdata.frame(omit.mon, index=c("cowcode_2", "year5"))

#set seed
set.seed(50)

#Run and summarize model
gmm.omit.mon <- pgmm(dr_1_at_2_m~Lmalaria_interp_2_m+Llog_trade_m+Llog_gdppc_2_m+Lln_cinc_2_m+
                       Ldemocracy_2_m| 
                       lag(dr_1_at_2_m, 2:5)+lag(Lmalaria_interp_2_m,2:5),
                     data = pgmm.omit.mon, 
                     effect = "twoway", transformation= "ld", model = "onestep")
summary(gmm.omit.mon)

##Number of observations
omit.mon.na <- na.omit(omit.mon)
length(omit.mon.na$dr_1_at_2_m)

################
###Table A.13###
################

##Keep only variables of interest
ni.mon <- mon.dat[,c("dr_1_at_2_m","Lcid_malaria_2_m","Llog_trade_m","Llog_gdppc_2_m","Lln_cinc_2_m","Ldemocracy_2_m","cowcode_2","year5")]

#Convert data to pgmm formal
pgmm.ni.mon <- pdata.frame(ni.mon, index=c("cowcode_2", "year5"))

#set seed
set.seed(50)

#Run and summarize model
gmm.ni.mon <- pgmm(dr_1_at_2_m~Lcid_malaria_2_m+Llog_trade_m+Llog_gdppc_2_m+Lln_cinc_2_m+
                     Ldemocracy_2_m| 
                     lag(dr_1_at_2_m, 2:5)+lag(Lcid_malaria_2_m,2:5),
                   data = pgmm.ni.mon, 
                   effect = "twoway", transformation= "ld", model = "onestep")
summary(gmm.ni.mon)

##Number of observations
ni.mon.na <- na.omit(mon.dat[,c("dr_1_at_2_m","Lcid_malaria_2_m","Llog_trade_m","Llog_gdppc_2_m","Lln_cinc_2_m","Ldemocracy_2_m","cowcode_2","year5")])
length(ni.mon.na$dr_1_at_2_m)

################
###Table A.15###
################

##Keep only variables of interest
pop.mon <- mon.dat[,c("dr_1_at_2_m","Lmalaria_interp_pop_2_m","Llog_trade_m","Llog_gdppc_2_m","Lln_cinc_2_m","Ldemocracy_2_m","cowcode_2","year5")]

#Convert data to pgmm formal
pgmm.pop.mon <- pdata.frame(pop.mon, index=c("cowcode_2", "year5"))

#set seed
set.seed(50)

#Run and summarize model
gmm.pop.mon <- pgmm(dr_1_at_2_m~Lmalaria_interp_pop_2_m+Llog_trade_m+Llog_gdppc_2_m+Lln_cinc_2_m+
                      Ldemocracy_2_m| 
                      lag(dr_1_at_2_m, 2:5)+lag(Lmalaria_interp_pop_2_m,2:5),
                    data = pgmm.pop.mon, 
                    effect = "twoway", transformation= "ld", model = "onestep")
summary(gmm.pop.mon)

##Number of observations
pop.mon.na <- na.omit(mon.dat[,c("dr_1_at_2_m","Lmalaria_interp_pop_2_m","Llog_trade_m","Llog_gdppc_2_m","Lln_cinc_2_m","Ldemocracy_2_m","cowcode_2","year5")])
length(pop.mon.na$dr_1_at_2_m)


################
###Table A.17###
################

##Keep only variables of interest
exp.mon <- mon.dat[,c("dr_1_at_2_m","L_total_exposure_2","Llog_trade_m","Llog_gdppc_2_m","Lln_cinc_2_m","Ldemocracy_2_m","cowcode_2","year5")]

#Convert data to pgmm formal
pgmm.exp.mon <- pdata.frame(exp.mon, index=c("cowcode_2", "year5"))

#set seed
set.seed(50)

#Run and summarize model
gmm.exp.mon <- pgmm(dr_1_at_2_m~L_total_exposure_2+Llog_trade_m+Llog_gdppc_2_m+Lln_cinc_2_m+
                      Ldemocracy_2_m| 
                      lag(dr_1_at_2_m, 2:5)+lag(L_total_exposure_2,2:5),
                    data = pgmm.exp.mon, 
                    effect = "twoway", transformation= "ld", model = "onestep")
summary(gmm.exp.mon)

##Number of observations
exp.mon.na <- na.omit(mon.dat[,c("dr_1_at_2_m","L_total_exposure_2","Llog_trade_m","Llog_gdppc_2_m","Lln_cinc_2_m","Ldemocracy_2_m","cowcode_2","year5")])
length(exp.mon.na$dr_1_at_2_m)


################
###Table A.21###
################

##Keep only variables of interest
cont.mon <- mon.dat[,c("dr_1_at_2_m","Lmalaria_interp_2_m","Llog_trade_m","Llog_gdppc_2_m","Lln_cinc_2_m","Ldemocracy_2_m","Linternal_conf_2_m","Lexternal_conf_2_m","Lln_irst_2_m","Lln_milex_2_m","Lln_milper_2_m","Lln_pec_2_m","Lln_upop_2_m","entryy_2_m","cowcode_2","year5")]

#Convert data to pgmm formal
pgmm.cont.mon <- pdata.frame(cont.mon, index=c("cowcode_2", "year5"))

#set seed
set.seed(50)

#Run and summarize model
gmm.cont.mon <- pgmm(dr_1_at_2_m~Lmalaria_interp_2_m+Llog_trade_m+Llog_gdppc_2_m+Lln_cinc_2_m+
                       Ldemocracy_2_m+Linternal_conf_2_m+Lexternal_conf_2_m+Lln_irst_2_m+
                       Lln_milex_2_m+Lln_milper_2_m+Lln_pec_2_m+Lln_upop_2_m+entryy_2_m| 
                       lag(dr_1_at_2_m, 2:5)+lag(Lmalaria_interp_2_m,2:5),
                     data = pgmm.cont.mon, 
                     effect = "twoway", transformation= "ld", model = "onestep")
summary(gmm.cont.mon)

##Number of observations
cont.mon.na <- na.omit(mon.dat[,c("dr_1_at_2_m","Lmalaria_interp_2_m","Llog_trade_m","Llog_gdppc_2_m","Lln_cinc_2_m","Ldemocracy_2_m","Linternal_conf_2_m","Lexternal_conf_2_m","Lln_irst_2_m","Lln_milex_2_m","Lln_milper_2_m","Lln_pec_2_m","Lln_upop_2_m","entryy_2_m","cowcode_2","year5")])
length(cont.mon.na$dr_1_at_2_m)


